package com.huiyuan.controller;

import com.huiyuan.common.Result;
import com.huiyuan.common.User;
import com.huiyuan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @author huiyuan080
 * @data 2023/5/3
 * @apiNote
 */
@RestController
@RequestMapping("member-service/member")
public class MemberController {


    @Autowired
    private UserService userService;

    /**
     * 用户充值服务
     * @param userId
     * @param price
     * @return
     */
    @PostMapping("recharge")
    public Result recharge(Integer userId, BigDecimal price) {
       userService.recharge(userId,price);
        return new Result();
    }

    /**
     * 修改用户是否用车
     * @param userId
     * @return
     */
    @GetMapping("addUse/{userId}")
    public Result addUse(@PathVariable Integer userId){
        userService.addUse(userId);
        return new Result();
    }

    /**
     * 查询用户是否租从车
     * @param userId
     * @return
     */
    @GetMapping("isNull/{userId}")
    public User isNull(@PathVariable Integer userId){
        User user = userService.isNull(userId);
        return user;
    }


    @PostMapping("update")
    public void update(@RequestBody User user){
        this.userService.updateByPrimaryKeySelective(user);
    }
}
